package com.my.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.resource.VersionResourceResolver;

/**
 * Created by Administrator on 2017/6/22.
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
   /* @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //http://ip:port/projectContext/error 访问 error.html
        registry.addViewController("/error").setViewName("error.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }*/

   /* @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        super.configurePathMatch(configurer);
        //路径参数如果带.的话(/projectContext/a.bb.html ,.后面的值将被忽略,配置configurePathMatch不忽略点后面的参数
        configurer.setUseSuffixPatternMatch(false);
    }*/

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        /**
         * 内置的VersionResourceResolver有FixedVersionStrategy和ContentVersionStrategy两种策略,
         * FixedVersionStrategy可以使用某项属性,或者日期,或者其它来作为版本.
         * 而ContentVersionStrategy是使用资源内容计算出来的MD5哈希作为版本.
         * ContentVersionStrategy是个不错的默认选择,除了某些不能使用的情况下(比如,带有javascript模块加截器).
         * 以下配置:如果是js的话使用FixedVersionStrategy,其它(如css,img)使用默认的ContentVersionStrategy策略.
         */
//        registry.addResourceHandler("/**").addResourceLocations("/static/")
//                .resourceChain(true)//开启缓存
//                .addResolver(new VersionResourceResolver().addFixedVersionStrategy("1.10", "/**/*.js").addContentVersionStrategy("/**"));
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
//        registry.addResourceHandler("/html/**").addResourceLocations("classpath:/static/html/");
        super.addResourceHandlers(registry);
    }
}